#include <bits/stdc++.h>
#define N 500001
using namespace std;
int n, m, s, cnt;

struct Edge
{
	int v, nxt;
} e[N<<1];
int heads[N];
inline void add(int u, int v)
{
	e[++cnt].v = v;
	e[cnt].nxt = heads[u];
	heads[u] = cnt;
}

int dep[N], fa[N][20];
int lca(int a, int b)
{
	if (dep[a] < dep[b])
		swap(a, b);
	for (int i = 19; ~i; --i)
		if (dep[fa[a][i]] >= dep[b])
			a = fa[a][i];
	if (a == b)
		return a;
	for (int j = 19; ~j; --j)
		if (fa[a][j] != fa[b][j])
			a = fa[a][j], b = fa[b][j];
	return fa[a][0];
}
void dfs(int x)
{
	for (int i = heads[x]; i; i = e[i].nxt)
	{
		if (e[i].v == fa[x][0])
			continue;
		dep[e[i].v] = dep[x] + 1;
		fa[e[i].v][0] = x;
		dfs(e[i].v);
	}
}
int main()
{
	// freopen("testdata.in", "r", stdin);
	// freopen("testdata.out", "w", stdout);
	scanf("%d %d %d", &n, &m, &s);
	int x, y, ans;
	for (int i = 1; i < n; ++i)
	{
		scanf("%d %d", &x, &y);
		add(x, y);
		add(y, x);
	}
	fa[s][0] = s;
	dfs(s);
	for (int i = 1; i < 20; ++i)
		for (int j = 1; j <= n; ++j)
			fa[j][i] = fa[fa[j][i - 1]][i - 1];
	for (int i = 0; i < m; ++i)
	{
		scanf("%d %d", &x, &y);
		ans = lca(x, y);
		printf("%d\n", ans);
	}
	// fclose(stdin);
	// fclose(stdout);
	return 0;
}